package com.lft.examsys.model;

import com.lft.examsys.exception.ValidationFailureException;
import com.lft.examsys.exception.ViewChangeException;
import com.lft.examsys.handler.ValidationFailureHandler;
import com.lft.examsys.handler.ValidationHandler;
import org.springframework.web.servlet.ModelAndView;

public class ValidationModelAndView extends ModelAndView {
    private ValidationHandler successHandler;
    private ValidationFailureHandler failureHandler;

    public ValidationModelAndView(String viewName, ValidationHandler successHandler, ValidationFailureHandler failureHandler) {
        super(viewName);
        this.successHandler = successHandler;
        this.failureHandler = failureHandler;
    }

    public void success() throws ValidationFailureException, ViewChangeException, Exception {
        successHandler.invoke();
    }

    public void failure(String message) {
        if (failureHandler != null)
            failureHandler.invoke(message);
    }
}
